﻿

<div class="block center">
    <h2>SignalR Chat</h2>
    <div class="inputBlock center">
        <input type="text" id="msg">
        <input class="button" id="broadcast" type="button" value="Send">
        <ul id="messages"></ul>
    </div>
</div>

@section scripts
{
    <script src="~/Scripts/jquery.signalR-1.0.0-alpha2.min.js"></script>
    <script src="~/signalr/hubs" type="text/javascript"></script>

    <script type="text/javascript">
        $(function () {
            
           var username = prompt('Please enter a username:');

           // Proxy created on the fly
           var chat = $.connection.chat;

           // Declare a function on the chat hub so the server can invoke it
           chat.client.addMessage = function (message) {
               $('#messages').append('<li>' + message + '</li>');
           };

           $("#broadcast").click(function () {
               // Call the chat method on the server
               chat.server.send({ message: $("#msg").val(), username: username });
           });

           // Start the connection
           $.connection.hub.start();
       });
    </script>
}